package chixing.day15.work;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class PhoneManager {
    public static Map<String, List<Phone>>phones = new HashMap<>();
    public static Map<String, List<Phone>> classifyPhones(List<Phone> phoneList) {
        Map<String, List<Phone>> classifiedMap = new HashMap<>();
        for (Phone phone : phoneList) {
            String brand = phone.getBrand();
            if (!classifiedMap.containsKey(brand)) {
                classifiedMap.put(brand, new ArrayList<>());
            }
            classifiedMap.get(brand).add(phone);
        }
        return classifiedMap;
    }
    public static void displayClassifiedPhones(Map<String, List<Phone>> classifiedMap) {
        for (Map.Entry<String, List<Phone>> entry : classifiedMap.entrySet()) {
            System.out.println("品牌：" + entry.getKey());
            for (Phone phone : entry.getValue()) {
                System.out.println(phone);
            }
            System.out.println("--------------------------------");
        }
    }
    public static void main(String[] args) {
    List<Phone> phones=new ArrayList<>();
        phones.add(new Phone("苹果", "iphone 15", 1999));
        phones.add(new Phone("小米", "Redmi K70", 3999));
        phones.add(new Phone("华为", "华为nova 11SE", 3999));
        phones.add(new Phone("华为", "华为70 Pro", 2999));
        phones.add(new Phone("OPPO", "OPPO K12x", 4999));
        phones.add(new Phone("苹果", "iphone 14", 6999));
        phones.add(new Phone("小米", "Redmi Note13", 1000));
        phones.add(new Phone("OPPO", "OPPO A1i", 1999));
        phones.add(new Phone("苹果", "iphone 13", 2999));
        phones.add(new Phone("华为", "华为mate60", 2999));
        phones.add(new Phone("华为", "华为nova12", 2999));
        phones.add(new Phone("小米", "小米 12C", 2888));
        phones.add(new Phone("苹果", "iphone 12", 1777));
        Map<String, List<Phone>> classifiedMap = classifyPhones(phones);
        displayClassifiedPhones(classifiedMap);
    }
}
